import QtQuick 2.0
import "../components"

Rectangle {

    property int startStep: 1
    property int endStep: 1
    property int cycleNum: 0
    property int stepNum: endStep - startStep + 1

    function setCycleNum(num){
        editor_cycleNum.setText(num)
        cycleNum = num
    }

    property bool isEditable: false

    id: root

    height: parent.height
    width: 215*dp * stepNum - 5*dp
    radius: 10*dp
    clip: true

    Rectangle{       // 黑条
        height: 100*dp
        width: parent.width
        color: "#656566"


        // 最上面不知道是干嘛的加减号
        Item{               // 左边的<
            height: 32*dp;   width: 15*dp
            x: 8*dp;    y: 7*dp
            opacity: 0.8
            Image{
                anchors.fill: parent
                source: "qrc:/picture/leftarrow2.png"
            }MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                onEntered: {
                    parent.opacity = 1
                }onExited: {
                    parent.opacity = 0.8
                }
                onReleased: {
                    if(!isEditable)  return
                    expandLeft(startStep)
                }
            }
        }Item{              // 左边的>
            visible: stepNum > 1
            opacity: 0.2
            height: 32*dp;   width: 15*dp
            x: 23*dp;    y: 7*dp
            Image{
                anchors.fill: parent
                source: "qrc:/picture/rightarrow2.png"
            }MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                onEntered: {
                    parent.opacity = 0.5
                }onExited: {
                    parent.opacity = 0.2
                }onReleased: {
                    if(!isEditable)  return
                    contractLeft(startStep)
                }
            }
        }Item{               // 右边的<
            visible: stepNum > 1
            opacity: 0.2
            height: 32*dp;   width: 15*dp
            x: parent.width - 38*dp;    y: 7*dp
            Image{
                anchors.fill: parent
                source: "qrc:/picture/leftarrow2.png"
            }MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                onEntered: {
                    parent.opacity = 0.5
                }onExited: {
                    parent.opacity = 0.2
                }onReleased: {
                    if(!isEditable)  return
                    contractRight(endStep)
                }
            }
        }Item{               // 右边的>
            height: 32*dp;   width: 15*dp
            x: parent.width - 23*dp;    y: 7*dp
            opacity: 0.8
            Image{
                anchors.fill: parent
                source: "qrc:/picture/rightarrow2.png"
            }MouseArea{
                anchors.fill: parent
                hoverEnabled: true
                cursorShape: Qt.PointingHandCursor
                onEntered: {
                    parent.opacity = 1
                }onExited: {
                    parent.opacity = 0.8
                }onReleased: {
                    if(!isEditable)  return
                    expandRight(endStep)
                }
            }
        }
        Item{
            height: 45*dp
            width: 60*dp
            anchors.horizontalCenter: parent.horizontalCenter
            Text{
                anchors.centerIn: parent
                text: stepNum === 1 ? "保温" : "扩增"
                color: "white"
                font.pixelSize: 20*dp
                font.bold: true
            }
        }



        //  循环数控制
        LineEditor{
            id: editor_cycleNum
            defaultText: cycleNum
            editWidth: 80*dp
            visible: stepNum > 1
            anchors.horizontalCenter: parent.horizontalCenter
            y: 50*dp
            intflag: true
            editable: root.isEditable
            onTextChanged: {
                if(!visible)    return
                cycleNum = Number(getText())
                if(cycleNum > 100 || cycleNum < 0){
                    mainwindow.showToast("循环范围为2到100", 1)
                    cycleNum = Math.max(Math.min(cycleNum, 100), 2)
                    setText(cycleNum)
                }

            }
        }
        Rectangle{
            height: 30*dp
            width: 30*dp
            visible: stepNum > 1
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.horizontalCenterOffset: -65*dp
            y: 55*dp
            color: "transparent"
            border.color: "white"
            border.width: 3*dp
            radius: 5*dp
            Text {
                text: qsTr("-")
                color: "white"
                font.bold: true
                font.pixelSize: 35*dp
                anchors.centerIn: parent
                anchors.verticalCenterOffset: -2*dp
            }
            MouseArea{
                anchors.fill: parent
                cursorShape: Qt.PointingHandCursor
                onReleased: {
                    if(!isEditable){
                        return
                    }
                    cycleNum = Math.max(Number(editor_cycleNum.getText()) - 1, 2)
                    cycleNum = Math.min(99, cycleNum)
                    editor_cycleNum.setText(cycleNum)
                }
            }
        }Rectangle{
            height: 30*dp
            width: 30*dp
            visible: stepNum > 1
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.horizontalCenterOffset: 65*dp
            y: 55*dp
            color: "transparent"
            border.color: "white"
            border.width: 3*dp
            radius: 5*dp
            Text {
                text: qsTr("+")
                color: "white"
                font.bold: true
                font.pixelSize: 30*dp
                anchors.centerIn: parent
                anchors.verticalCenterOffset: -2*dp
            }
            MouseArea{
                anchors.fill: parent
                cursorShape: Qt.PointingHandCursor
                onReleased: {
                    if(!isEditable){
                        return
                    }
                    cycleNum = Number(editor_cycleNum.getText()) + 1
                    editor_cycleNum.setText(cycleNum)
                }
            }
        }
    }
}
